<template>
    <div class="app-container">
        <h1>轮播图管理列表</h1>

        <!-- 表格 -->
        <el-table
        :data="list"
        border
        fit
        highlight-current-row>

        <el-table-column
            label="序号"
            width="70"
            align="center">
            <template slot-scope="scope">
            {{ (current - 1) * limit + scope.$index + 1 }}
            </template>
        </el-table-column>

        <el-table-column prop="title" label="轮播图标题" width="150" />

        <el-table-column prop="linkUrl" label="链接地址" width="100"/>

        <!-- 图片显示 -->
        <el-table-column prop="imageUrl" align="center" label="图片地址" width="250">
          <template slot-scope="scope">
            <img :src="scope.row.imageUrl" min-width="70" height="70">
          </template>
        </el-table-column>

        <el-table-column prop="sort" label="排序" width="100" />

        <el-table-column prop="gmtCreate" label="添加时间" width="160"/>

        <el-table-column label="操作" width="220" align="center">
            <template slot-scope="scope">
            <router-link :to="'/banner/edit/'+scope.row.id">
                <el-button type="primary" size="mini" icon="el-icon-edit">修改轮播图</el-button>
            </router-link>
            <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)">删除</el-button>
            </template>
        </el-table-column>
        </el-table>

        <!-- 分页组件 -->
        <el-pagination
            :current-page="current"
            :page-size="limit"
            :total="total"
            style="text-align: center; padding: 30px 0"
            layout="total, prev, pager, next, jumper"
            @current-change="queryCoursePage"
        />
    </div>
</template>

<script>
// 引入调用teacher.js文件
import banner from '@/api/edu/banner'
export default {
  data() {
    return {
      list: null,// 查询之后接口的返回集合
      current: 1,// 当前页
      limit: 4,// 每页显示的记录数
      total: 0,// 总记录数
    }
  },
  created() {
    this.queryBannerPage()
  },
  methods: {

    // 轮播图列表带分页
    queryBannerPage(current = 1) {
      this.current = current
      banner.queryBannerPage(this.current, this.limit)
        .then(response => {
            this.list = response.data.items;
            this.total = response.data.Total;
        })
    },

    // 删除轮播图的方法
    removeDataById(id) {
      this.$confirm('此操作将永久删除该轮播图, 是否继续?', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
      }).then(() => {
        // 调用后台删除的方法
        banner.deleteBannerById(id)
          .then(response => {
            // 提示信息
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            // 删除后回到列表页面
            this.queryBannerPage()
          })
      });
    }
  }
  
}
</script>